package com.centaline.androidsalesblog.adapter;

import android.content.Context;
import android.view.View;

import com.bumptech.glide.DrawableRequestBuilder;
import com.centaline.androidsalesblog.R;
import com.centaline.androidsalesblog.adapter.viewholder.EstateNewsVH;
import com.centaline.androidsalesblog.iml.RecyclerViewItemOnClickListener;
import com.centaline.androidsalesblog.model.businissobject.CollectInfoChangeBo;
import com.centaline.androidsalesblog.model.databaseobject.EsfEstateDo;
import com.centaline.androidsalesblog.utils.DateUtil;
import com.centanet.framework.base.BaseAdapter1;

import java.util.ArrayList;

/**
 * 小区动态
 * Created by guilin on 16/3/30.
 */
public class EsfNewsAdapter extends BaseAdapter1<EstateNewsVH> {

    final DrawableRequestBuilder<String> requestBuilder;
    final ArrayList<CollectInfoChangeBo> list;
    final RecyclerViewItemOnClickListener<CollectInfoChangeBo> itemOnClickListener;

    public EsfNewsAdapter(Context context, DrawableRequestBuilder<String> requestBuilder, ArrayList<CollectInfoChangeBo> list,
                          RecyclerViewItemOnClickListener<CollectInfoChangeBo> itemOnClickListener) {
        super(context);
        this.requestBuilder = requestBuilder;
        this.list = list;
        this.itemOnClickListener = itemOnClickListener;
    }

    @Override
    protected int inflateByLayoutId() {
        return R.layout.item_news_estate;
    }

    @Override
    protected EstateNewsVH viewHolder(View view) {
        return new EstateNewsVH(view);
    }

    @Override
    public void onBindViewHolder(EstateNewsVH holder, int position) {
        final CollectInfoChangeBo collectInfoChangeBo = list.get(position);
        final EsfEstateDo esfEstateDo = collectInfoChangeBo.getEsfEstateDo();
        holder.img_news_point.setVisibility(collectInfoChangeBo.isRead() ? View.INVISIBLE : View.VISIBLE);
        if (esfEstateDo != null) {
//            GlideLoad.load(new GlideLoad.Builder(requestBuilder, esfEstateDo.getDefaultImg())
//                    .placeHolder(R.drawable.ic_centa_square_logo)
//                    .error(R.drawable.ic_centa_square_logo)
//                    .openWifiSwitch()
//                    .into(holder.img_logo));
            holder.tv_my_message_content.setText("您关注的【" + esfEstateDo.getName() + "】房源有变化啦，赶快围观吧！");
//            holder.atv_tag_fir.setText(String.format(Locale.CHINA, "%d室%d厅  %.2f平  %s",
//                    esfEstateDo.getBedroomCount(),
//                    esfEstateDo.getSittingRoomCount(),
//                    esfEstateDo.getSize(),
//                    esfEstateDo.getDirection()));
            holder.tv_my_message_time.setText(DateUtil.timeRule(collectInfoChangeBo.getUpdateTime2() * 1000));
//            holder.atv_price.setText(PriceUtil.salePrice(esfEstateDo.getPrice()));
//            holder.customListTagView.setTags(postDo.getKeyWords());
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemOnClickListener.onItemOnClick(collectInfoChangeBo, 0);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
